<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
    <title>Choway Blog</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="七尘的个人博客">
    <meta name="keywords" content="java、python、SpringBoot、Hibernate">
    <link rel="shortcut icon" href="/images/favicon.ico">
    <link rel="stylesheet" href="/css/animate.min.css">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/kratos.diy.css">
    <link rel="stylesheet" href="/css/layer.min.css">
    <link rel="stylesheet" href="/css/superfish.min.css">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/hoverIntent.min.js"></script>
    <script src="/js/jquery.easing.min.js"></script>
    <script src="/js/jquery.qrcode.min.js"></script>
    <script src="/js/jquery.stellar.min.js"></script>
    <script src="/js/jquery.waypoints.min.js"></script>
    <script src="/js/kratos.diy.js"></script>
    <script src="/js/kratos.js"></script>
    <script src="/js/layer.min.js"></script>
    <script src="/js/modernizr.min.js"></script>
    <script src="/js/superfish.js"></script>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-dark.min.css">
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
    <script type="text/javascript">
      hljs.initHighlightingOnLoad();
    </script>
</head>


<body data-spy="scroll" data-target=".scrollspy">
    <div id="kratos-wrapper">
        <div id="kratos-page">
            <div id="kratos-header">
    <header id="kratos-header-section">
        <div class="container">
            <div class="nav-header">
                <a href="#" class="js-kratos-nav-toggle kratos-nav-toggle"><i></i></a>
                <h1 id="kratos-logo"><a href="/">Choway Blog</a></h1>
                
                <nav id="kratos-menu-wrap">
                  <ul id="kratos-primary-menu" class="sf-menu">
                  
                    <li>
                      <a href="/categories/Java/">Java</a>
                    </li>
                  
                    <li>
                      <a href="/categories/DevOps/">DevOps</a>
                    </li>
                  
                  </ul>
                </nav>
            </div>
        </div>
    </header>
</div>

<div class="kratos-start kratos-hero-2 kratos-post-header">
    <div class="kratos-overlay kratos-post" style="background:#222831"></div>
</div>
            
            <div id="kratos-blog-post" style="background:#f5f5f5;">
                <div class="container">
                    <div class="row">
                        <section id="main" class="col-md-8">
                            <!--  文章模板  -->
<article>
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            <h1 class="kratos-entry-title text-center">docker 基本操作</h1>
            <div class="kratos-post-meta text-center">
                <span>
                    <i class="fa fa-commenting-o"></i> choway
                    <i class="fa fa-calendar"></i> 2018-12-18 02:37:09
                    <i class="fa fa-eye"></i> 
                    
                        <a class="category-link" href="/categories/DevOps/">DevOps</a><a class="category-link" href="/categories/DevOps/Docker/">Docker</a>
                    
                </span>
            </div>
        </header>
        <div class="kratos-post-content">
            <a id="more"></a>
<h2 id="查看-docker-环境"><a href="#查看-docker-环境" class="headerlink" title="查看 docker 环境"></a>查看 docker 环境</h2><pre><code class="bash">$ docker -v
$ docker version
$ docker info
</code></pre>
<h2 id="docker-设置镜像加速"><a href="#docker-设置镜像加速" class="headerlink" title="docker 设置镜像加速"></a>docker 设置镜像加速</h2><ol>
<li>[centos] 在 /etc/docker/ 目录下建立 daemon.json 文件</li>
</ol>
<pre><code class="json">{
  &quot;registry-mirrors&quot;: [&quot;https://mirror-id.mirror.aliyuncs.com&quot;]
}
</code></pre>
<ol start="2">
<li>然后执行</li>
</ol>
<pre><code class="bash">$ systemctl daemon-reload
$ systemctl restart docker
</code></pre>
<h2 id="镜像操作"><a href="#镜像操作" class="headerlink" title="镜像操作"></a>镜像操作</h2><h5 id="从仓库获取镜像"><a href="#从仓库获取镜像" class="headerlink" title="从仓库获取镜像"></a>从仓库获取镜像</h5><pre><code class="bash">$ docker pull
$ docker pull --help
</code></pre>
<h5 id="列出本地镜像"><a href="#列出本地镜像" class="headerlink" title="列出本地镜像"></a>列出本地镜像</h5><pre><code class="bash">$ docker image ls
$ docker images
</code></pre>
<h5 id="删除本地镜像"><a href="#删除本地镜像" class="headerlink" title="删除本地镜像"></a>删除本地镜像</h5><pre><code class="bash">$ docker image rm IMAGE_ID
$ docker rmi IMAGE_ID
</code></pre>
<h2 id="容器操作"><a href="#容器操作" class="headerlink" title="容器操作"></a>容器操作</h2><h5 id="查看容器"><a href="#查看容器" class="headerlink" title="查看容器"></a>查看容器</h5><pre><code class="bash">$ docker ps 查看启动的容器
$ docker ps -a 查看所有容器，包括已停止的容器
</code></pre>
<h5 id="创建并启动容器"><a href="#创建并启动容器" class="headerlink" title="创建并启动容器"></a>创建并启动容器</h5><pre><code class="bash">$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre>
<p>OPTIONS 常用选项：<br>-p 将本地端口和容器端口进行映射，如 -p 80:8080；<br>-d 后台运行容器；<br>-i 将容器的标准输入一直打开；<br>-t 让容器分配一个伪终端（pseudo-tty）并绑定到容器的标准输入上；<br>-v 挂载数据卷：将本地目录和容器目录进行映射，从而达到多容器实例之间共享数据目录；</p>
<h5 id="停止容器"><a href="#停止容器" class="headerlink" title="停止容器"></a>停止容器</h5><pre><code class="bash">$ docker stop CONTAINER
</code></pre>
<h5 id="启动一个停止的容器"><a href="#启动一个停止的容器" class="headerlink" title="启动一个停止的容器"></a>启动一个停止的容器</h5><pre><code class="bash">$ docker start CONTAINER
</code></pre>
<h5 id="重启容器"><a href="#重启容器" class="headerlink" title="重启容器"></a>重启容器</h5><pre><code class="bash">$ docker restart CONTAINER
</code></pre>
<h5 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h5><pre><code class="bash">$ docker rm CONTAINER
</code></pre>
<h5 id="获取容器的输出信息"><a href="#获取容器的输出信息" class="headerlink" title="获取容器的输出信息"></a>获取容器的输出信息</h5><pre><code class="bash">$ docker logs CONTAINER
</code></pre>
<h5 id="进入容器"><a href="#进入容器" class="headerlink" title="进入容器"></a>进入容器</h5><pre><code class="bash">$ docker exec -i -t CONTAINER /bin/bash
</code></pre>
<h5 id="容器拷贝（本地）文件"><a href="#容器拷贝（本地）文件" class="headerlink" title="容器拷贝（本地）文件"></a>容器拷贝（本地）文件</h5><pre><code class="bash">$ docker cp
</code></pre>

        </div>
        <footer class="kratos-entry-footer clearfix">
            <div class="post-like-donate text-center clearfix" id="post-like-donate">

            </div>
            <div class="footer-tag clearfix">
                <div class="pull-left">
                    <i class="fa fa-tags"></i>
                    
                        <a class="tag-link" href="/tags/docker/">docker</a>
                    
                </div>
            </div>
        </footer>
    </div>
    <div class="kratos-hentry kratos-copyright text-center clearfix">
        <img alt="知识共享许可协议" src="/images/licenses.png">
        <h5>本作品采用 <a rel="license nofollow" target="_blank" href="http://creativecommons.org/licenses/by-sa/4.0/">知识共享署名-相同方式共享 4.0 国际许可协议</a> 进行许可</h5>
    </div>

    
    <nav class="navigation post-navigation clearfix" role="navigation">
        
        <div class="nav-previous clearfix">
            <a title="springboot redis 实现 session 共享" href="/springboot-redis-session.html">&lt; 上一篇</a>
        </div>
        
        
        <div class="nav-next">
            <a title="Dockerfile 编写" href="/dockerfile-command.html">下一篇 &gt;</a>
        </div>
        
    </nav>
    
</article>
                        </section>

                        <aside id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm scrollspy">
                            <div id="sidebar">
    <aside id="kratos_about-2" class="widget amadeus_about clearfix">
        <div class="photo-background">
            <div class="photo-background" style="background:url(/images/about_bg.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;"></div>
        </div>
        <div class="photo-wrapper clearfix">
            <div class="photo-wrapper-tip text-center">
                <a href="/"><img class="about-photo" src="/images/about_me.jpg" /></a>
            </div>
        </div>
        <div class="textwidget">
            <p style="text-align: center;font-weight:400;">Choway Blog<br />七尘的个人博客</p>
        </div>
    </aside>

    
    <aside class="widget clearfix">
        <h4 class="widget-title">文章目录</h4>
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看-docker-环境"><span class="toc-text">查看 docker 环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#docker-设置镜像加速"><span class="toc-text">docker 设置镜像加速</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#镜像操作"><span class="toc-text">镜像操作</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#从仓库获取镜像"><span class="toc-text">从仓库获取镜像</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#列出本地镜像"><span class="toc-text">列出本地镜像</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#删除本地镜像"><span class="toc-text">删除本地镜像</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#容器操作"><span class="toc-text">容器操作</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#查看容器"><span class="toc-text">查看容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#创建并启动容器"><span class="toc-text">创建并启动容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#停止容器"><span class="toc-text">停止容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#启动一个停止的容器"><span class="toc-text">启动一个停止的容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#重启容器"><span class="toc-text">重启容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#删除容器"><span class="toc-text">删除容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#获取容器的输出信息"><span class="toc-text">获取容器的输出信息</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#进入容器"><span class="toc-text">进入容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#容器拷贝（本地）文件"><span class="toc-text">容器拷贝（本地）文件</span></a></li></ol></li></ol></li></ol></li></ol>
    </aside>
    

    
    <aside class="widget clearfix">
        <h4 class="widget-title">文章分类</h4>
        <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/DevOps/">DevOps</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/DevOps/ActiveMQ/">ActiveMQ</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/DevOps/Docker/">Docker</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/JVM/">JVM</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/SpringBoot/">SpringBoot</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/SpringCloud/">SpringCloud</a></li></ul></li></ul>
    </aside>
    

    
    <aside class="widget clearfix">
        <h4 class="widget-title">标签聚合</h4>
        <div class="tag_clouds">
            <a class="tag-link" href="/tags/activemq/">activemq</a><a class="tag-link" href="/tags/centos/">centos</a><a class="tag-link" href="/tags/docker/">docker</a><a class="tag-link" href="/tags/hotspot/">hotspot</a><a class="tag-link" href="/tags/java/">java</a><a class="tag-link" href="/tags/jms/">jms</a><a class="tag-link" href="/tags/jvm/">jvm</a><a class="tag-link" href="/tags/redis/">redis</a><a class="tag-link" href="/tags/spring-cloud/">spring cloud</a><a class="tag-link" href="/tags/springboot/">springboot</a>
        </div>
    </aside>
    

</div>
                        </aside>
                    </div>
                </div>
            </div>

            <footer>
    <div id="footer">
        <div class="cd-tool visible-lg text-center">
            <a class="cd-top cd-is-visible cd-fade-out"><span class="fa fa-chevron-up"></span></a>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <p class="kratos-social-icons">
                        <a target="_blank" rel="nofollow" href="https://github.com/choway"><i class="fa fa-github"></i></a>
                    </p>
                    <p>Copyright 2020 <a href="/">Choway Blog</a>. All Rights Reserved.
                </div>
            </div>
        </div>
    </div>
</footer>
        </div>
    </div>
</body>
</html>